// pages/newsDetail/newsDetail.js
var app=getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    host: app.d.hostImg,
    hotGoods:[],
    // poster: 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000',
    name:0,
    // author: '许巍',
    src: 0,
    mp4:0,
    bofang:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function (options) {
    var news_id=options.news_id;
    var store_id=app.d.store_Id;
    var that = this;
    wx.request({
        url: app.d.ceshiUrl + '/Api/News/detail',
        method: 'POST',
        data: {
          news_id: news_id, 
          store_id: store_id,
        },
        header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        success: function(res) {
         var info = res.data.info ;
         var content = info.content;
         var hotgood = info.goods;
         console.log(content);
            WxParse.wxParse('content', 'html', content, that,3);
            that.setData({
               info: info,
               hotGoods: hotgood,
               name:info.name,
               src:info.audio,
               mp4:info.mp4

           })
        }
    })

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady(res) {
    this.audioCtx = wx.createAudioContext('myAudio')
    // this.audioCtx.play()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
  toGoodsDetail:function(e){
    var pro_id=e.target.id
     wx.navigateTo({
     url: '../product/detail?pro_id=' + pro_id,
   })
   },
   bofang:function(e){
    var that=this;
      if(that.data.bofang==1){
          that.audioCtx.play()
          that.setData({
              bofang:0
           })
      }else{
          that.audioCtx.pause()
           that.setData({
              bofang:1
           })
      }
   },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '',
      path: '',
      success: function (res) {
        // 分享成功
      },
      fail: function (res) {
        // 分享失败
      }
    }
  },
})